const Router = require('koa-router')
const router = new Router()

const login = require('./admin/login')
const index = require('./admin/index')

router.use(async (ctx, next) => {
  if (ctx.session.userInfo) {
    await next()
  } else {
    // 没有登录就跳转到登录页面
    if (ctx.url === '/admin/login' || ctx.url === '/admin/login/doLogin') {
      await next()
    } else {
      ctx.redirect('/admin/login')
    }
  }
})
router.use('/index', index)
router.use('/login', login)

module.exports = router.routes()
